/**
 * http://code.google.com/p/gwt-spot
 * 
 * GWT-Spot -- Copyright 2008-2009
 *          -- by Dunkel, Ricardo
 *  
 */
package de.ricardodunkel.gwtspot.client.api.common;

import java.util.List;
import java.util.Map;

import com.google.gwt.dom.client.Node;
import com.google.gwt.dom.client.NodeList;

/**
 * Utility class for common <em>collection</em> handling.
 * 
 * @author Dunkel, Ricardo
 * 
 * @version 0.1
 *
 */
public class CollectionUtility {

	/**
	 * Decide weather or not a {@link Map} seems to be empty.
	 * 
	 * @param map  A <em>map</em> to validate.
	 * 
	 * @return  <strong>True</strong> if <em>map</em> is empty
	 * 			or null, <strong>false</strong> otherwise.
	 */
	public static boolean isEmpty(Map map) {
		if( null == map || map.size() == 0 ) {
			return true;
		} else {
			return false;
		}
	}
	
	/**
	 * Inverting {@link #isEmpty(Map)}.
	 * 
	 * @param list  A <em>map</em> to validate.
	 * 
	 * @return  <strong>True</strong> if <em>map</em> is not
	 * 			 empty, <strong>false</strong> otherwise.
	 */
	public static boolean isNotEmpty(Map map) {
		return !isEmpty(map);
	}
	
	/**
	 * Decide weather or not a {@link List} seems to be empty.
	 * 
	 * @param list  A <em>list</em> to validate.
	 * 
	 * @return  <strong>True</strong> if <em>list</em> is empty
	 * 			or null, <strong>false</strong> otherwise.
	 */
	public static boolean isEmpty(List list) {
		if( null == list || list.size() == 0 ) {
			return true;
		} else {
			return false;
		}
	}
	
	/**
	 * Inverting {@link #isEmpty(List)}.
	 * 
	 * @param list  A <em>list</em> to validate.
	 * 
	 * @return  <strong>True</strong> if <em>list</em> is 
	 * 			not empty, <strong>false</strong> otherwise.
	 */
	public static boolean isNotEmpty(List list) {
		return !isEmpty(list);
	}

	/**
	 * Decide weather or not a {@link NodeList} seems to be empty.
	 * 
	 * @param list  A <em>node list</em> to validate.
	 * 
	 * @return  <strong>True</strong> if <em>node list</em> is empty
	 * 			or null, <strong>false</strong> otherwise.
	 */
	public static boolean isEmpty(NodeList<Node> elements) {
		if( null == elements || elements.getLength() == 0 ) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * Inverting {@link #isEmpty(NodeList)}.
	 * 
	 * @param list  A <em>node list</em> to validate.
	 * 
	 * @return  <strong>True</strong> if <em>node list</em> is
	 * 			not empty, <strong>false</strong> otherwise.
	 */
	public static boolean isNotEmpty(NodeList<Node> elements) {
		return !isEmpty(elements);
	}
	
}
